package com.yurun.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 宫静雨
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yurun"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Testing\t" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
                .description("宫静雨")
                .version("v1.0")
                .termsOfServiceUrl("http://10.11.0.215:5172/wiki1510426/index.html?file=000-%E9%9B%A8%E6%B6%A6API%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3/099-%E9%9B%A8%E6%B6%A6%E7%AE%A1%E5%9F%B9%E7%94%9F%E6%B5%8B%E8%AF%95%E9%A1%B9%E7%9B%AE/100101-YR100101-%E5%AD%A6%E7%94%9F%E5%88%97%E8%A1%A8%E6%9F%A5%E8%AF%A2")
                .build();
    }
}